#include<Python.h>
#include"structmember.h"
#include"SimpleDecoder.h"
#include"Decoder.h"

#include<mad.h>

PyMODINIT_FUNC PyInit_madsimple(void);

void debug_print(PyObject *obj) {
	PyObject_Print(obj, stderr, Py_PRINT_RAW);
}

extern PyObject *
madsimple_system(PyObject *self, PyObject *args);

static PyMethodDef MadSimpleMethods[] = {
	{NULL, NULL, 0, NULL}
};

static struct PyModuleDef madsimple = {
	PyModuleDef_HEAD_INIT,
	"madsimple",     /* name of module */
	NULL,
	-1,
	MadSimpleMethods /* is defined above */
};

static PyObject *MadsimpleError;

PyMODINIT_FUNC
PyInit_madsimple(void)
{
	PyObject *m, *o, *d;
	int rtn;

	if (PyType_Ready(&SDecoderType) < 0)
		return NULL;
	if (PyType_Ready(&DecoderType) < 0)
		return NULL;

	m = PyModule_Create(&madsimple);
	if (m == NULL){;
		return NULL;
	}

	Py_INCREF(&SDecoderType);
	PyModule_AddObject(m, "SimpleDecoder", (PyObject*)&SDecoderType);

	Py_INCREF(&DecoderType);
	PyModule_AddObject(m, "Decoder", (PyObject*)&DecoderType);

	/* Add some symbolic constants to the module */
	d = PyModule_GetDict(m);
	if (d == NULL)
		return NULL;

	/* module attributes.  */
	o = PyLong_FromLong((long) MAD_FLOW_STOP);
	if (!o) return NULL;
	rtn = PyDict_SetItemString(d, "FLOW_STOP", o);
	Py_DECREF(o);
	if (rtn!=0) return NULL;

	o = PyLong_FromLong((long) MAD_FLOW_CONTINUE);
	if (!o) return NULL;
	rtn = PyDict_SetItemString(d, "FLOW_CONTINUE", o);
	Py_DECREF(o);
	if (rtn!=0) return NULL;

	o = PyLong_FromLong((long) MAD_FLOW_BREAK);
	if (!o) return NULL;
	rtn = PyDict_SetItemString(d, "FLOW_BREAK", o);
	Py_DECREF(o);
	if (rtn!=0) return NULL;
		

	MadsimpleError = PyErr_NewException("madsimple.error", NULL, NULL);
	Py_INCREF(MadsimpleError);
	PyModule_AddObject(m, "error", MadsimpleError);

	return m;
}


